package VerifyCodeGenerator;

import java.util.Random;
import java.util.Scanner;

public class VerifyCodeGenerator {
    public static void main(String[] args)
    {
        String code = generateVerifyCode(6);
        System.out.println("生成的验证码为："+ code);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入验证码：");
        String inputCode = sc.nextLine().toLowerCase();

        if(inputCode.equals(code.toLowerCase()))
        {
            System.out.println("恭喜验证成功！");
        }
        else
        {
            System.out.println("验证失败！");
        }
        sc.close();
    }
    public static String generateVerifyCode(int length) {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

        for (int i = 0; i < length; i++) {
            int index = random.nextInt(chars.length());
            sb.append(chars.charAt(index));
        }
        return sb.toString();
    }
}
